home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / CNet Word 2 XML / CNet Word 2 XML.msi / _A457BDB7B2E17DFFF7E6FDD111D1D0F9 / _E876D44CCE7B576F00E9E9CF12B12E35 < prev   
Encoding:
Extensible Markup Language  |  2002-12-21  |  6.3 KB  |  211 lines

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <xsl:stylesheet version="1.0" 
  3.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  4.     xmlns:h="http://www.w3.org/1999/xhtml" 
  5.     xmlns:w2x="urn:schemas-docsoft-com:word-to-xml:extensions" 
  6.     xmlns:o="urn:schemas-microsoft-com:office:office"
  7.     exclude-result-prefixes="h w2x o">
  8.     
  9.     <xsl:output method="xml" encoding="utf-8" indent="yes"  
  10.             omit-xml-declaration="no" />
  11.  
  12.     <xsl:template match="h:style|h:script|h:xml" />
  13.     <xsl:template match="w2x:hide|w2x:script" />
  14.     
  15.     <xsl:template match="/">
  16.         <article>
  17.             <articleinfo>
  18.                 <title>
  19.                     <xsl:for-each select="h:html/h:head/h:title">
  20.                         <xsl:value-of select="." />
  21.                     </xsl:for-each>
  22.                 </title>
  23.                 <xsl:apply-templates select="//o:documentproperties" />
  24.             </articleinfo>
  25.             <xsl:apply-templates select="h:html/h:body" />
  26.         </article>
  27.     </xsl:template>
  28.     <xsl:template match="o:documentproperties">
  29.         <xsl:if test="o:author">
  30.             <author>
  31.                 <xsl:choose>
  32.                     <xsl:when test="contains(o:author, ' ')">
  33.                         <firstname>
  34.                             <xsl:value-of select="substring-before(o:author, ' ')" />
  35.                         </firstname>
  36.                         <surname>
  37.                             <xsl:value-of select="substring-after(o:author, ' ')" />
  38.                         </surname>
  39.                     </xsl:when>
  40.                     <xsl:otherwise>
  41.                         <othername>
  42.                             <xsl:value-of select="o:author" />
  43.                         </othername>
  44.                     </xsl:otherwise>
  45.                 </xsl:choose>
  46.             </author>
  47.         </xsl:if>
  48.         <xsl:if test="o:company">
  49.             <corpname>
  50.                 <xsl:value-of select="o:company" />
  51.             </corpname>
  52.         </xsl:if>
  53.         <xsl:if test="o:lastsaved">
  54.             <date>
  55.                 <xsl:value-of select="o:lastsaved" />
  56.             </date>
  57.         </xsl:if>
  58.     </xsl:template>
  59.     <xsl:template match="h:body">
  60.         <xsl:apply-templates />
  61.     </xsl:template>
  62.     <xsl:template match="h:div[parent::h:body]">
  63.         <section>
  64.                 <xsl:apply-templates />
  65.         </section>
  66.     </xsl:template>
  67.     <xsl:template match="h:p">
  68.         <para>
  69.             <xsl:apply-templates />
  70.         </para>
  71.     </xsl:template>
  72.     <xsl:template match="h:ol|h:div[attribute::w2x:list-type]">
  73.         <orderedlist>
  74.             <xsl:apply-templates />
  75.         </orderedlist>
  76.     </xsl:template>
  77.     <xsl:template match="h:ul|h:div[attribute::w2x:list-type = 'bullet']">
  78.         <itemizedlist>
  79.             <xsl:apply-templates />
  80.         </itemizedlist>
  81.     </xsl:template>
  82.     <xsl:template match="h:span[attribute::w2x:list-item-number]" />
  83.     <xsl:template match="h:li|h:*[attribute::w2x:list-item-class]">
  84.         <listitem>
  85.             <xsl:for-each select="*|text()">
  86.                 <xsl:choose>
  87.                 <xsl:when test="not(self::h:span or self::text())">
  88.                     <xsl:apply-templates  select="." />
  89.                 </xsl:when>
  90.                 <xsl:when test="normalize-space(.) = ''" />
  91.                 <xsl:otherwise>
  92.                    <para><xsl:apply-templates select="." /></para>
  93.                 </xsl:otherwise>
  94.                 </xsl:choose>
  95.             </xsl:for-each>
  96.         </listitem>
  97.     </xsl:template>
  98.     <xsl:template match="h:img">
  99.         <figure>
  100.             <title><xsl:value-of select="attribute::alt" /></title>
  101.             <graphic fileref="{attribute::src}"/>
  102.         </figure>
  103.     </xsl:template>
  104.     <xsl:template match="h:a">
  105.         <anchor id="{attribute::name}" />
  106.     </xsl:template>
  107.     <xsl:template match="h:a[attribute::href]">
  108.         <ulink url="{attribute::href}">
  109.             <xsl:apply-templates />
  110.         </ulink>
  111.     </xsl:template>
  112.     <xsl:template match="h:a[starts-with(attribute::href, '#')]">
  113.         <link linkend="{substring-after(attribute::href, '#')}">
  114.             <xsl:apply-templates />
  115.         </link>
  116.     </xsl:template>
  117.     <xsl:template match="h:b|h:i|h:strong">
  118.         <emphasis>
  119.             <xsl:apply-templates />
  120.         </emphasis>
  121.     </xsl:template>
  122.     <xsl:template match="h:table">
  123.         <table>
  124.             <xsl:if test="h:caption">
  125.                 <title>
  126.                     <xsl:value-of select="h:cation" />
  127.                 </title>
  128.             </xsl:if>
  129.             <xsl:variable name="cols"><xsl:apply-templates select=".//h:tr[1]/*[position() = last()]" mode="count-cols-before" /></xsl:variable>
  130.             <tgroup cols="{$cols}">
  131.                 <xsl:call-template name="print-cols">
  132.                     <xsl:with-param name="col" select="number($cols)" />
  133.                 </xsl:call-template>
  134.                 <tbody>
  135.                     <xsl:apply-templates />
  136.                 </tbody>
  137.             </tgroup>
  138.         </table>
  139.     </xsl:template>
  140.     <xsl:template name="print-cols">
  141.         <xsl:param name="col" />
  142.         <xsl:if test="$col > 0">
  143.             <xsl:call-template name="print-cols">
  144.                 <xsl:with-param name="col" select="$col - 1" />
  145.             </xsl:call-template>
  146.             <colspec colname="c{$col}" />
  147.         </xsl:if>
  148.     </xsl:template>
  149.     <xsl:template match="*" mode="count-cols-before">
  150.         <xsl:variable name="cols-before"><xsl:apply-templates select="preceding-sibling::*[1]" mode="count-cols-before" /></xsl:variable>
  151.         <xsl:choose>
  152.             <xsl:when test="attribute::colspan != '' and $cols-before != ''">
  153.                 <xsl:value-of select="number($cols-before) + number(attribute::colspan)" />
  154.             </xsl:when>
  155.             <xsl:when test="attribute::colspan != ''">
  156.                 <xsl:value-of select="number(attribute::colspan)" />
  157.             </xsl:when>
  158.             <xsl:when test="$cols-before != ''">
  159.                 <xsl:value-of select="number($cols-before) + 1" />
  160.             </xsl:when>
  161.             <xsl:otherwise>
  162.                 <xsl:value-of select="1" />
  163.             </xsl:otherwise>
  164.         </xsl:choose>
  165.     </xsl:template>
  166.     <xsl:template match="h:tr">
  167.         <row>
  168.             <xsl:apply-templates />
  169.         </row>
  170.     </xsl:template>
  171.     <xsl:template match="h:td|h:th">
  172.         <entry>
  173.             <xsl:if test="attribute::rowspan != ''">
  174.                 <xsl:attribute name="morerows">
  175.                     <xsl:value-of select="number(attribute::rowspan) - 1" />
  176.                 </xsl:attribute>
  177.             </xsl:if>
  178.             <xsl:if test="attribute::colspan != ''">
  179.                 <xsl:variable name="cols-before">
  180.                     <xsl:apply-templates select="preceding-sibling::*[1]" mode="count-cols-before" />
  181.                 </xsl:variable>
  182.                 <xsl:attribute name="namest">c<xsl:value-of select="number($cols-before) + 1" /></xsl:attribute>
  183.                 <xsl:attribute name="nameend">c<xsl:value-of select="number($cols-before) + number(attribute::colspan)" /></xsl:attribute>
  184.             </xsl:if>
  185.             <xsl:if test="attribute::align != ''">
  186.                 <xsl:attribute name="align">
  187.                     <xsl:value-of select="attribute::align" />
  188.                 </xsl:attribute>
  189.             </xsl:if>
  190.             <xsl:apply-templates />
  191.         </entry>
  192.     </xsl:template>
  193.     
  194.     <xsl:template match="h:div[attribute::w2x:header-level]">
  195.         <section>
  196.             <sectioninfo>
  197.                 <title><xsl:apply-templates select="*[1]" mode="title" /></title>
  198.             </sectioninfo>
  199.             <xsl:apply-templates />
  200.         </section>
  201.     </xsl:template>
  202.  
  203.     <xsl:template match="h:h1|h:h2|h:h3|h:h4|h:h5" />
  204.     
  205.     <xsl:template match="*" mode="title" />
  206.     <xsl:template match="h:h1|h:h2|h:h3|h:h4|h:h5" mode="title">
  207.         <xsl:value-of select="." />
  208.     </xsl:template> 
  209.     
  210. </xsl:stylesheet>
  211.